import {SelectType} from "./props";
import * as Taro from "@tarojs/taro";

class Files {
    constructor() {
    }

    /**
     * 选择文件
     * @param type              文件类型，默认 file
     * @param count             个数，默认1个
     * @param extension         限制扩展名
     */
    choose(type?: keyof SelectType, count?: number, extension?: string[]): Promise<Taro.chooseMessageFile.SuccessCallbackResult> {
        return new Promise((resolve, reject) => {
            Taro.chooseMessageFile({
                type: type ?? 'file',
                count: count ?? 1,
                extension,
                success: (files) => {
                    console.log('files', files)
                    return resolve(files)
                },
                fail: (err) => {
                    reject(err)
                }
            }).then()
        })
    }
}

const files = new Files();

export default files
